import { ajax } from '../lib/ajax.js';
import { tools } from '../lib/tools.js';

let txt_tname = document.getElementById('txt_tname');
let txt_league = document.getElementById('txt_league');
let txt_champions = document.getElementById('txt_champions');
let txt_cups = document.getElementById('txt_cups');
let txt_goals = document.getElementById('txt_goals');
let txt_gname = document.getElementById('txt_gname');
let txt_fans = document.getElementById('txt_fans');
let txt_created = document.getElementById('txt_created');
let txt_intro = document.getElementById('txt_intro');
let btnOk = document.getElementById('btnOk');
let btnBack = document.getElementById('btnBack');

btnOk.addEventListener('click', () => {
  let add = {
    tname: txt_tname.value,
    league: txt_league.value,
    intro: txt_intro.value,
    champions: txt_champions.value,
    cups: txt_cups.value,
    fans: txt_fans.value,
    goals: txt_goals.value,
    gname: txt_gname.value,
    created: txt_created.value,
  };

  ajax.post('/crud/footballteam', add, (data) => {
    alert(data.message);
    if (data.success) {
      txt_tname.value = '';
      txt_league.value = '';
      txt_intro.value = '';
      txt_champions.value = '';
      txt_cups.value = '';
      txt_fans.value = '';
      txt_goals.value = '';
      txt_gname.value = '';
      txt_created.value = '';
    }
  });
});


btnBack.addEventListener('click', () => {
  location.href = 'fbt.html';
});